home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 December / 2004-12 CHIP.iso / Narzedzia systemowe / Inno Setup 5.0.4 Beta / isetup-5.0.4-beta.exe / {app} / Examples / CodeAutomation.iss (.txt) next >
Encoding:
Inno Setup Script  |  2004-08-02  |  8.0 KB  |  190 lines

  1. ; -- CodeAutomation.iss --
  2. ; This script shows how to use the COM Automation object support.
  3. [Setup]
  4. AppName=My Program
  5. AppVerName=My Program version 1.5
  6. CreateAppDir=no
  7. DisableProgramGroupPage=yes
  8. DefaultGroupName=My Program
  9. UninstallDisplayIcon={app}\MyProg.exe
  10. [Code]
  11. {--- SQLDMO ---}
  12. const
  13.   SQLServerName = 'localhost';
  14.   SQLDMOGrowth_MB = 0;
  15. procedure SQLDMOButtonOnClick(Sender: TObject);
  16.   SQLServer, Database, DBFile, LogFile: Variant;
  17.   IDColumn, NameColumn, Table: Variant;
  18. begin
  19.   if MsgBox('Setup will now connect to Microsoft SQL Server ''' + SQLServerName + ''' via a trusted connection and create a database. Do you want to continue?', mbInformation, mb_YesNo) = idNo then
  20.     Exit;
  21.   { Create the main SQLDMO COM Automation object }
  22.   try
  23.     SQLServer := CreateOleObject('SQLDMO.SQLServer');
  24.   except
  25.     RaiseException(ExceptionType, 'Please install Microsoft SQL server connectivity tools first.'#13#13'(Error '''+ExceptionParam+''' occured)');
  26.   end;
  27.   { Connect to the Microsoft SQL Server }
  28.   SQLServer.LoginSecure := True;
  29.   SQLServer.Connect(SQLServerName);
  30.   MsgBox('Connected to Microsoft SQL Server ''' + SQLServerName + '''.', mbInformation, mb_Ok);
  31.   { Setup a database }
  32.   Database := CreateOleObject('SQLDMO.Database');
  33.   Database.Name := 'Inno Setup';
  34.   DBFile := CreateOleObject('SQLDMO.DBFile');
  35.   DBFile.Name := 'ISData1';
  36.   DBFile.PhysicalName := 'c:\program files\microsoft sql server\mssql\data\IS.mdf';
  37.   DBFile.PrimaryFile := True;
  38.   DBFile.FileGrowthType := SQLDMOGrowth_MB;
  39.   DBFile.FileGrowth := 1;
  40.   Database.FileGroups.Item('PRIMARY').DBFiles.Add(DBFile);
  41.   LogFile := CreateOleObject('SQLDMO.LogFile');
  42.   LogFile.Name := 'ISLog1';
  43.   LogFile.PhysicalName := 'c:\program files\microsoft sql server\mssql\data\IS.ldf';
  44.   Database.TransactionLog.LogFiles.Add(LogFile);
  45.   { Add the database }
  46.   SQLServer.Databases.Add(Database);
  47.   MsgBox('Added database ''' + Database.Name + '''.', mbInformation, mb_Ok);
  48.   { Setup some columns }
  49.   IDColumn := CreateOleObject('SQLDMO.Column');
  50.   IDColumn.Name := 'id';
  51.   IDColumn.Datatype := 'int';
  52.   IDColumn.Identity := True;
  53.   IDColumn.IdentityIncrement := 1;
  54.   IDColumn.IdentitySeed := 1;
  55.   IDColumn.AllowNulls := False;
  56.   NameColumn := CreateOleObject('SQLDMO.Column');
  57.   NameColumn.Name := 'name';
  58.   NameColumn.Datatype := 'varchar';
  59.   NameColumn.Length := '64';
  60.   NameColumn.AllowNulls := False;
  61.   { Setup a table }
  62.   Table := CreateOleObject('SQLDMO.Table');
  63.   Table.Name := 'authors';
  64.   Table.FileGroup := 'PRIMARY';
  65.   { Add the columns and the table }
  66.   Table.Columns.Add(IDColumn);
  67.   Table.Columns.Add(NameColumn);
  68.   Database.Tables.Add(Table);
  69.   MsgBox('Added table ''' + Table.Name + '''.', mbInformation, mb_Ok);
  70. {--- IIS ---}
  71. const
  72.   IISServerName = 'localhost';
  73.   IISServerNumber = '1';
  74.   IISURL = 'http://127.0.0.1';
  75. procedure IISButtonOnClick(Sender: TObject);
  76.   IIS, WebSite, WebServer, WebRoot, VDir: Variant;
  77.   ErrorCode: Integer;
  78. begin
  79.   if MsgBox('Setup will now connect to Microsoft IIS Server ''' + IISServerName + ''' and create a virtual directory. Do you want to continue?', mbInformation, mb_YesNo) = idNo then
  80.     Exit;
  81.   { Create the main IIS COM Automation object }
  82.   try
  83.     IIS := CreateOleObject('IISNamespace');
  84.   except
  85.     RaiseException(ExceptionType, 'Please install Microsoft IIS first.'#13#13'(Error '''+ExceptionParam+''' occured)');
  86.   end;
  87.   { Connect to the IIS server }
  88.   WebSite := IIS.GetObject('IIsWebService', IISServerName + '/w3svc');
  89.   WebServer := WebSite.GetObject('IIsWebServer', IISServerNumber);
  90.   WebRoot := WebServer.GetObject('IIsWebVirtualDir', 'Root');
  91.   { (Re)create a virtual dir }
  92.   try
  93.     WebRoot.Delete('IIsWebVirtualDir', 'innosetup');
  94.     WebRoot.SetInfo();
  95.   except
  96.   end;
  97.   VDir := WebRoot.Create('IIsWebVirtualDir', 'innosetup');
  98.   VDir.AccessRead := True;
  99.   VDir.AppFriendlyName := 'Inno Setup';
  100.   VDir.Path := 'C:\inetpub\innosetup';
  101.   VDir.AppCreate(True);
  102.   VDir.SetInfo();
  103.   MsgBox('Created virtual directory ''' + VDir.Path + '''.', mbInformation, mb_Ok);
  104.   { Write some html and display it }
  105.   if MsgBox('Setup will now write some HTML and display the virtual directory. Do you want to continue?', mbInformation, mb_YesNo) = idNo then
  106.     Exit;
  107.   ForceDirectories(VDir.Path);
  108.   SaveStringToFile(VDir.Path + '/index.htm', '<html><body>Inno Setup rocks!</body></html>', False);
  109.   if not ShellExec('open', IISURL + '/innosetup/index.htm', '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode) then
  110.     MsgBox('Can''t display the created virtual directory: ''' + SysErrorMessage(ErrorCode) + '''.', mbError, mb_Ok);
  111. {--- MSXML ---}
  112. const
  113.   XMLURL = 'http://cvs.jrsoftware.org/view/*checkout*/ishelp/isxfunc.xml';
  114.   XMLFileName = 'isxfunc.xml';
  115.   XMLFileName2 = 'isxfuncmodified.xml';
  116. procedure MSXMLButtonOnClick(Sender: TObject);
  117.   XMLHTTP, XMLDoc, NewNode, RootNode: Variant;
  118.   Path: String;
  119. begin
  120.   if MsgBox('Setup will now use MSXML to download XML file ''' + XMLURL + ''' and save it to disk.'#13#13'Setup will then load, modify and save this XML file. Do you want to continue?', mbInformation, mb_YesNo) = idNo then
  121.     Exit;
  122.   { Create the main MSXML COM Automation object }
  123.   try
  124.     XMLHTTP := CreateOleObject('MSXML2.ServerXMLHTTP');
  125.   except
  126.     RaiseException(ExceptionType, 'Please install MSXML first.'#13#13'(Error '''+ExceptionParam+''' occured)');
  127.   end;
  128.   { Download the XML file }
  129.   XMLHTTP.Open('GET', XMLURL, False);
  130.   XMLHTTP.Send();
  131.   Path := ExpandConstant('{src}\');
  132.   XMLHTTP.responseXML.Save(Path + XMLFileName);
  133.   MsgBox('Downloaded the XML file and saved it as ''' + XMLFileName + '''.', mbInformation, mb_Ok);
  134.   { Load the XML File }
  135.   XMLDoc := CreateOleObject('MSXML2.DOMDocument');
  136.   XMLDoc.async := False;
  137.   XMLDoc.resolveExternals := False;
  138.   XMLDoc.load(Path + XMLFileName);
  139.   if XMLDoc.parseError.errorCode <> 0 then
  140.     RaiseException(erCustomError, 'Error on line ' + IntToStr(XMLDoc.parseError.line) + ', position ' + IntToStr(XMLDoc.parseError.linepos) + ': ' + XMLDoc.parseError.reason);
  141.   MsgBox('Loaded the XML file.', mbInformation, mb_Ok);
  142.   { Modify the XML document }
  143.   NewNode := XMLDoc.createElement('isxdemo');
  144.   RootNode := XMLDoc.documentElement;
  145.   RootNode.appendChild(NewNode);
  146.   RootNode.lastChild.text := 'Hello, World';
  147.   { Save the XML document }
  148.   XMLDoc.Save(Path + XMLFileName2);
  149.   MsgBox('Saved the modified XML as ''' + XMLFileName2 + '''.', mbInformation, mb_Ok);
  150. {--- Word ---}
  151. procedure WordButtonOnClick(Sender: TObject);
  152.   Word: Variant;
  153. begin
  154.   if MsgBox('Setup will now check whether Microsoft Word is running. Do you want to continue?', mbInformation, mb_YesNo) = idNo then
  155.     Exit;
  156.   { Try to get an active Word COM Automation object }
  157.   try
  158.     Word := GetActiveOleObject('Word.Application');
  159.   except
  160.   end;
  161.   if VarIsEmpty(Word) then
  162.     MsgBox('Microsoft Word is not running.', mbInformation, mb_Ok)
  163.   else
  164.     MsgBox('Microsoft Word is running.', mbInformation, mb_Ok)
  165. {---}
  166. procedure CreateButton(ALeft, ATop: Integer; ACaption: String; ANotifyEvent: TNotifyEvent);
  167. begin
  168.   with TButton.Create(WizardForm) do begin
  169.     Left := ALeft;
  170.     Top := ATop;
  171.     Width := WizardForm.CancelButton.Width;
  172.     Height := WizardForm.CancelButton.Height;
  173.     Caption := ACaption;
  174.     OnClick := ANotifyEvent;
  175.     Parent := WizardForm;
  176.   end;
  177. procedure InitializeWizard();
  178.   Left, Top, TopInc: Integer;
  179. begin
  180.   Left := WizardForm.WelcomeLabel2.Left;
  181.   TopInc := WizardForm.CancelButton.Height + 8;
  182.   Top := WizardForm.WelcomeLabel2.Top + WizardForm.WelcomeLabel2.Height - 4*TopInc;
  183.   CreateButton(Left, Top, '&SQLDMO...', @SQLDMOButtonOnClick);
  184.   Top := Top + TopInc;
  185.   CreateButton(Left, Top, '&IIS...', @IISButtonOnClick);
  186.   Top := Top + TopInc;
  187.   CreateButton(Left, Top, '&MSXML...', @MSXMLButtonOnClick);
  188.   Top := Top + TopInc;
  189.   CreateButton(Left, Top, '&Word...', @WordButtonOnClick);
  190.